#include "oled_driver.h"
#include "app_qspi.h"
#include "app_qspi_dma.h"
#include "app_dspi.h"
#include "app_dspi_dma.h"
#include "board_SK.h"
#include "app_log.h"
#define DSPI_DATA_LEN                       (100)
#define DSPI_POXEL_LEN                      (57600)
#define DSPI_DMA_SIZE                       (4094 * 2)
#define DSPI_SOFT_CS_MODE_ENABLE            1u

#define DSPI_DATA_SRAM
#define DSPI_ST7789V_X_START                0
#define DSPI_ST7789V_X_END                  239
#define DSPI_ST7789V_Y_START                40
#define DSPI_ST7789V_Y_END                  319
static volatile uint8_t                     g_master_tdone = 0;
static dspi_command_t                       g_cmd;
static uint8_t                              s_data_8[DSPI_DATA_LEN] = {0};
static uint16_t                             s_data_16[DSPI_DATA_LEN] = {0};
#if defined(DSPI_DATA_SRAM)
static uint16_t                             pixel[DSPI_POXEL_LEN] = {0};
#endif
static volatile uint8_t                     display_busy = 0;
static volatile uint32_t                    display_xfer_remain = 0;
static uint8_t                              *display_xfer_point = NULL;

void init_oled_periph(void)
{
	// 1. init oled power
		uint16_t ret;
    app_io_init_t io_init = APP_IO_DEFAULT_CONFIG;
    app_io_pin_state_t pin_val;
    int cnt = 10;

    io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = APP_OLED_POWER_PIN;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_OLED_POWER_TYPE, &io_init);
    if (ret != APP_DRV_SUCCESS)
    {
       // printf("APP_GPIO_PIN0 init failed.\r\n");
    }

		
		io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = APP_AVDD_POWER_PIN;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_AVDD_POWER_TYPE, &io_init);
    if (ret != APP_DRV_SUCCESS)
    {
       // printf("APP_GPIO_PIN0 init failed.\r\n");
    }
		
		io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = APP_SYS_POWER_PIN;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_SYS_POWER_TYPE, &io_init);
    if (ret != APP_DRV_SUCCESS)
    {
       // printf("APP_GPIO_PIN0 init failed.\r\n");
    }
		io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = TFT_PWM_PIN;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_IO_TYPE_AON, &io_init);
		app_io_write_pin(APP_IO_TYPE_AON,TFT_PWM_PIN,APP_IO_PIN_SET);

    if (ret != APP_DRV_SUCCESS)
    {
        printf("APP_GPIO_PIN0 init failed.\r\n");
    }
		io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = APP_IO_PIN_1;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_IO_TYPE_MSIO, &io_init);
    if (ret != APP_DRV_SUCCESS)
    {
       // printf("APP_GPIO_PIN0 init failed.\r\n");
    }
		io_init.pull = APP_IO_NOPULL;
    io_init.mode = APP_IO_MODE_OUTPUT;
    io_init.pin  = APP_IO_PIN_0;
    io_init.mux  = APP_IO_MUX;
    ret = app_io_init(APP_IO_TYPE_MSIO, &io_init);
		delay_ms(40);
		app_io_write_pin(APP_IO_TYPE_MSIO,APP_IO_PIN_0,APP_IO_PIN_SET);
		delay_ms(40);
		app_io_write_pin(APP_IO_TYPE_MSIO,APP_IO_PIN_0,APP_IO_PIN_RESET);
		delay_ms(40);
		app_io_write_pin(APP_IO_TYPE_MSIO,APP_IO_PIN_0,APP_IO_PIN_SET);
		delay_ms(5);
		
    if (ret != APP_DRV_SUCCESS)
    {
       // printf("APP_GPIO_PIN0 init failed.\r\n");
    }
}
app_dspi_params_t dspi_params = {
    .pin_cfg = {
        .cs = {
             .type   = APP_IO_TYPE_MSIO,
            .mux    = APP_IO_MUX_7,
            .pin    = APP_IO_PIN_1,
           // .mode   = APP_IO_MODE_OUTPUT,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .clk = {
            .type   = APP_DSPI_CLK_TYPE,
            .mux    = APP_DSPI_CLK_PIN_MUX,
            .pin    = APP_DSPI_CLK_PIN,
            .pull   = APP_DSPI_CLK_PULL,
            .enable = APP_DSPI_CLK_ENABLE,
        },
        .mosi = {
            .type   = APP_DSPI_MOSI_TYPE,
            .mux    = APP_DSPI_MOSI_PIN_MUX,
            .pin    = APP_DSPI_MOSI_PIN,
            .pull   = APP_DSPI_MOSI_PULL,
            .enable = APP_DSPI_MOSI_ENABLE,
        },
        .miso = {
            .type   = APP_DSPI_MISO_TYPE,
            .mux    = APP_DSPI_MISO_PIN_MUX,
            .pin    = APP_DSPI_MISO_PIN,
            .pull   = APP_DSPI_MISO_PULL,
            .enable = APP_DSPI_MISO_ENABLE,
        },
        .dcx = {
            .type   = APP_DSPI_DCX_TYPE,
            .mux    = APP_DSPI_DCX_PIN_MUX,
            .pin    = APP_DSPI_DCX_PIN,
            .pull   = APP_DSPI_DCX_PULL,
            .enable = APP_DSPI_DCX_ENABLE,
        },
    },
    .dma_cfg.channel = DMA_Channel0,
    .init = {
        .data_size = DSPI_DATASIZE_08_BITS,
        .baud_rate = DSPI_BAUD_RATE_64P1PCLK,
        .dspi_mode = DSPI_PROT_MODE_3W1L,
    },
    .is_soft_cs = true,
};
static app_qspi_params_t g_qspi_params = {
    .id = APP_QSPI_ID_2,
    .pin_cfg = {
        .cs = {
            .type   = APP_IO_TYPE_MSIO,
            .mux    = APP_IO_MUX_7,
            .pin    = APP_IO_PIN_1,
            .mode   = APP_IO_MODE_OUTPUT,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .clk = {
            .type   = APP_QSPI2_CLK_IO_TYPE,
            .mux    = APP_IO_MUX_2,
            .pin    = APP_QSPI2_CLK_PIN,
            .mode   = APP_IO_MODE_MUX,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .io_0 = {
            .type   = APP_QSPI2_CLK_IO_TYPE,
            .mux    = APP_IO_MUX_2,
            .pin    = APP_QSPI2_IO0_PIN,
            .mode   = APP_IO_MODE_MUX,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .io_1 = {
            .type   = APP_QSPI2_CLK_IO_TYPE,
            .mux    = APP_IO_MUX_2,
            .pin    = APP_QSPI2_IO1_PIN,
            .mode   = APP_IO_MODE_MUX,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .io_2 = {
            .type   = APP_QSPI2_CLK_IO_TYPE,
            .mux    = APP_IO_MUX_0,
            .pin    = APP_FLASH_IO2_PIN,
            .mode   = APP_IO_MODE_MUX,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
        .io_3 = {
            .type   = APP_QSPI2_CLK_IO_TYPE,
            .mux    = APP_IO_MUX_0,
            .pin    = APP_FLASH_IO3_PIN,
            .mode   = APP_IO_MODE_MUX,
            .pull   = APP_IO_PULLUP,
            .enable = APP_QSPI_PIN_ENABLE,
        },
    },
    .dma_cfg = {
        .dma_instance = DMA1,
        .dma_channel  = DMA_Channel3,
			 
    },
    .init = {
        .clock_mode      = QSPI_CLOCK_MODE_0,
        .clock_prescaler = 64u,
        .rx_sample_delay = 0,
    },
};


static void app_qspi_callback(app_qspi_evt_t *p_evt)
{
    if (p_evt->type == APP_QSPI_EVT_TX_CPLT)
    {
        g_master_tdone = 1;
    }
    if (p_evt->type == APP_QSPI_EVT_RX_DATA)
    {
       // g_master_rdone = 1;
    }
    if (p_evt->type == APP_QSPI_EVT_ERROR)
    {
        g_master_tdone = 1;
       // g_master_rdone = 1;
    }
}
uint8_t buffer[10];
void Solomon_VPA(unsigned char data)
{
app_dspi_dma_transmit_async(&data,1);
}
void Solomon_VMD(unsigned char cmd)
{
g_cmd.instruction = cmd;
    g_cmd.instruction_size = DSPI_INSTSIZE_08_BITS;
    g_cmd.data_size = DSPI_DATASIZE_08_BITS;
    g_cmd.length = 1;

    g_master_tdone = 0;
    app_dspi_dma_command_async(&g_cmd);
    while(g_master_tdone == 0);
}
void write_CMD(char cmd)
{
		g_cmd.instruction = cmd;
    g_cmd.instruction_size = DSPI_INSTSIZE_08_BITS;
    g_cmd.data_size = DSPI_DATASIZE_08_BITS;
    g_cmd.length = 1;

    g_master_tdone = 0;
    app_dspi_dma_command_async(&g_cmd);
    while(g_master_tdone == 0);
	  
}
void write_CMD_DATA(char cmd,uint8_t *pdata,char len)
{
		g_cmd.instruction = cmd;
    g_cmd.instruction_size = DSPI_INSTSIZE_08_BITS;
    g_cmd.data_size = DSPI_DATASIZE_08_BITS;
    g_cmd.length = len;

    g_master_tdone = 0;
    app_dspi_dma_command_transmit_async(&g_cmd, (uint8_t *)s_data_8);
    while(g_master_tdone == 0);
	  
		
	
}	
static void app_dspi_evt_handler(app_dspi_evt_t *p_evt)
{
    if (p_evt->type == APP_DSPI_EVT_TX_CPLT)
    {
       g_master_tdone = 1;
//        if (display_busy == 1)
//        {
//            if (display_xfer_remain != 0)
//            {
//                if (display_xfer_remain > DSPI_DMA_SIZE)
//                {
//                    app_dspi_display_xfer_start(display_xfer_point, DSPI_DMA_SIZE);
//                    display_xfer_remain -= DSPI_DMA_SIZE;
//                    display_xfer_point += DSPI_DMA_SIZE;
//                }
//                else
//                {
//                    app_dspi_display_xfer_start(display_xfer_point, DSPI_DMA_SIZE);
//                    display_xfer_remain = 0;
//                    display_xfer_point += display_xfer_remain;
//                }
//            }
//            else
//            {
//                display_busy = 0;
//            }
//        }
    }

    if (p_evt->type == APP_DSPI_EVT_ERROR)
    {
    }
}
void app_dspi_display_init(void)
{
   // gpio_init_t gpio_config = GPIO_DEFAULT_CONFIG;
    uint16_t ret = APP_DRV_ERR_HAL;

//    gpio_config.mode = GPIO_MODE_OUTPUT;
//    gpio_config.pull = GPIO_PULLDOWN;
//    gpio_config.pin  = GPIO_PIN_1
//    hal_gpio_init(GPIO0, &gpio_config);

   // hal_gpio_write_pin(GPIO0, GPIO_PIN_8 | GPIO_PIN_9, GPIO_PIN_SET);
 
//	  ret = app_qspi_init(&g_qspi_params, app_qspi_callback);
//    if (ret != APP_DRV_SUCCESS)
//    {
//        printf("Initialize QSPI failed\r\n");
//    }
		ret = app_dspi_init(&dspi_params, app_dspi_evt_handler);
    if (ret != APP_DRV_SUCCESS)
    {
        printf("Initialize DSPI failed\r\n");
    }
    delay_ms(100);
		 ret = app_dspi_dma_init(&dspi_params);
    if (ret != APP_DRV_SUCCESS)
    {
        printf("Initialize DSPI DMA failed\r\n");
    }
    delay_ms(100);
		
//		s_data_8[0]=0x98;s_data_8[1]=0x51;s_data_8[2]=0xE9;
//	  while(1)
//			Solomon_VPA(0x55);
//		write_CMD_DATA(0xDF,s_data_8,1);
//		s_data_8[0]=0x00;
//		write_CMD_DATA(0xDE,s_data_8,1);
//		
//		s_data_8[0]=0x1E;s_data_8[1]=0x85;s_data_8[2]=0x21;s_data_8[3]=0x30;
//		write_CMD_DATA(0xB7,s_data_8,4);
//		
//		s_data_8[0]=0x3F;s_data_8[1]=0x30;s_data_8[2]=0x27;s_data_8[3]=0x24;
//		s_data_8[4]=0x26;s_data_8[5]=0x28;s_data_8[6]=0x23;s_data_8[7]=0x22;
//		s_data_8[8]=0x22;s_data_8[9]=0x22;s_data_8[10]=0x20;s_data_8[11]=0x17;
//		s_data_8[12]=0x13;s_data_8[13]=0x0E;s_data_8[14]=0x08;s_data_8[15]=0x08;
//		s_data_8[16]=0x3F;s_data_8[17]=0x30;s_data_8[18]=0x27;s_data_8[19]=0x24;
//		s_data_8[20]=0x26;s_data_8[21]=0x28;s_data_8[22]=0x23;s_data_8[23]=0x22;
//		s_data_8[24]=0x22;s_data_8[25]=0x22;s_data_8[26]=0x20;s_data_8[27]=0x17;
//		s_data_8[28]=0x13;s_data_8[29]=0x0E;s_data_8[30]=0x08;s_data_8[31]=0x08;
//		write_CMD_DATA(0xC8,s_data_8,32);
//		
//		s_data_8[0]=0x33;s_data_8[1]=0x28;s_data_8[2]=0xCC;
//		write_CMD_DATA(0xB9,s_data_8,3);
//		
//		s_data_8[0]=0x0A;s_data_8[1]=0x39;s_data_8[2]=0x20;s_data_8[3]=0x30;s_data_8[4]=0x6C;
//		s_data_8[5]=0x60;s_data_8[6]=0x60;s_data_8[7]=0x70;
//		write_CMD_DATA(0xBB,s_data_8,8);
//		s_data_8[0]=0x38;s_data_8[1]=0x3C;
//		write_CMD_DATA(0xBC,s_data_8,2);
//		s_data_8[0]=0x12;s_data_8[1]=0x20;
//		write_CMD_DATA(0xC0,s_data_8,3);
//		
//		s_data_8[0]=0x12;
//		write_CMD_DATA(0xC1,s_data_8,1);
//		
//		s_data_8[0]=0x35;s_data_8[1]=0x30;
//		write_CMD_DATA(0xC2,s_data_8,2);
//		
//		s_data_8[0]=0x08;s_data_8[1]=0x00;s_data_8[2]=0x0A;s_data_8[3]=0x10;
//		s_data_8[4]=0x08;s_data_8[5]=0x68;s_data_8[6]=0x45;s_data_8[7]=0x81;
//		s_data_8[8]=0x2C;
//		write_CMD_DATA(0xC3,s_data_8,9);
//		
//		s_data_8[0]=0x00;s_data_8[1]=0x8E;s_data_8[2]=0x87;s_data_8[3]=0x0E;
//		s_data_8[4]=0x0A;s_data_8[5]=0x16;s_data_8[6]=0x87;s_data_8[7]=0x0E;
//		s_data_8[8]=0x0A;s_data_8[9]=0x16;s_data_8[10]=0x87;s_data_8[11]=0x0E;
//		s_data_8[12]=0x0A;s_data_8[13]=0x16;s_data_8[14]=0x82;s_data_8[15]=0x00;
//		s_data_8[16]=0x03;
//		write_CMD_DATA(0xC4,s_data_8,17);
//		
//		s_data_8[0]=0x04;s_data_8[1]=0x0C;s_data_8[2]=0x7B;s_data_8[3]=0x0F;
//		s_data_8[4]=0x01;s_data_8[5]=0x03;
//		write_CMD_DATA(0xD0,s_data_8,6);
//		
//		s_data_8[0]=0x00;s_data_8[1]=0x00;
//		write_CMD_DATA(0xD7,s_data_8,2);	
//		s_data_8[0]=0x02;s_data_8[1]=0x00;
//		write_CMD_DATA(0xDE,s_data_8,1);	
//		s_data_8[0]=0x7A;s_data_8[1]=0x04;
//		write_CMD_DATA(0xC4,s_data_8,2);
//		
//		s_data_8[0]=0x1D;s_data_8[1]=0xA0;s_data_8[2]=0x2F;s_data_8[3]=0x04;
//		s_data_8[4]=0x24;
//		write_CMD_DATA(0xB8,s_data_8,5);
//		
//		s_data_8[0]=0x1D;s_data_8[1]=0xA0;s_data_8[2]=0x2F;s_data_8[3]=0x04;
//		s_data_8[4]=0x24;
//		write_CMD_DATA(0xB2,s_data_8,5);
//		
//		s_data_8[0]=0x10;s_data_8[1]=0x66;s_data_8[2]=0x66;s_data_8[3]=0x01;
//		write_CMD_DATA(0xC1,s_data_8,4);
//		
//		s_data_8[0]=0x00;
//		write_CMD_DATA(0xDE,s_data_8,1);
//		s_data_8[0]=0x05;
//		write_CMD_DATA(0x3A,s_data_8,1);
//		
//		//////////////////////////
//		write_CMD(0x11);
//		delay_ms(200);
//		s_data_8[0]=0x00;s_data_8[1]=0x00;s_data_8[2]=0x00;s_data_8[3]=0xEF;
//		write_CMD_DATA(0x2A,s_data_8,4);
//		
//		s_data_8[0]=0x00;s_data_8[1]=0x00;s_data_8[2]=0x01;s_data_8[3]=0x1A;
//		write_CMD_DATA(0x2B,s_data_8,4);
//		
//		write_CMD(0x2C);
//		write_CMD(0x29);
		
	Solomon_VMD(0xDF); //Password
Solomon_VPA(0x98);
Solomon_VPA(0x51);
Solomon_VPA(0xE9);

Solomon_VMD(0xDE);
Solomon_VPA(0x00);

Solomon_VMD(0xB7);
Solomon_VPA(0x1E);
Solomon_VPA(0x85);
Solomon_VPA(0x21);
Solomon_VPA(0x30);

Solomon_VMD(0xC8);     //gamma2.5     //gamma2.0
Solomon_VPA(0x3F);     //0x3F         //0x35
Solomon_VPA(0x30);     //0x2E         //0x32
Solomon_VPA(0x27);     //0x25         //0x2F
Solomon_VPA(0x24);     //0x21         //0x32
Solomon_VPA(0x26);     //0x23         //0x37
Solomon_VPA(0x28);     //0x24         //0x3F
Solomon_VPA(0x23);     //0x1F         //0x3D
Solomon_VPA(0x22);     //0x1F         //0x3E
Solomon_VPA(0x22);     //0x1E         //0x3D
Solomon_VPA(0x22);     //0x1E         //0x3D
Solomon_VPA(0x20);     //0x1B         //0x3B
Solomon_VPA(0x17);     //0x11         //0x2E
Solomon_VPA(0x13);     //0x0C         //0x28
Solomon_VPA(0x0E);     //0x06         //0x1F
Solomon_VPA(0x08);     //0x02         //0x17
Solomon_VPA(0x08);     //0x08         //0x0E
Solomon_VPA(0x3F);     //0x3F         //0x35
Solomon_VPA(0x30);     //0x2F         //0x31
Solomon_VPA(0x27);     //0x26         //0x2F
Solomon_VPA(0x24);     //0x22         //0x31
Solomon_VPA(0x26);     //0x24         //0x36
Solomon_VPA(0x28);     //0x25         //0x3E
Solomon_VPA(0x23);     //0x20         //0x3D
Solomon_VPA(0x22);     //0x1F         //0x3E
Solomon_VPA(0x22);     //0x1F         //0x3D
Solomon_VPA(0x22);     //0x1F         //0x3D
Solomon_VPA(0x20);     //0x1C         //0x3B
Solomon_VPA(0x17);     //0x11         //0x2E
Solomon_VPA(0x13);     //0x0C         //0x28
Solomon_VPA(0x0E);     //0x06         //0x1F
Solomon_VPA(0x08);     //0x02         //0x17
Solomon_VPA(0x08);     //0x08         //0x0E

Solomon_VMD(0xB9);
Solomon_VPA(0x33);
Solomon_VPA(0x28);
Solomon_VPA(0xCC);

Solomon_VMD(0xBB);
Solomon_VPA(0x0A);
Solomon_VPA(0x39);
Solomon_VPA(0x20);
Solomon_VPA(0x30);
Solomon_VPA(0x6C);
Solomon_VPA(0x60);
Solomon_VPA(0x60);
Solomon_VPA(0x70);

Solomon_VMD(0xBC);
Solomon_VPA(0x38);
Solomon_VPA(0x3C);

Solomon_VMD(0xC0);
Solomon_VPA(0x12);
Solomon_VPA(0x20);

Solomon_VMD(0xC1);
Solomon_VPA(0x12);

Solomon_VMD(0xC2);
Solomon_VPA(0x08);
//Solomon_VPA(0x30);

Solomon_VMD(0xC3);
Solomon_VPA(0x08);
Solomon_VPA(0x00);
Solomon_VPA(0x0A);
Solomon_VPA(0x10);
Solomon_VPA(0x08);
Solomon_VPA(0x68);
Solomon_VPA(0x45);
Solomon_VPA(0x81);
Solomon_VPA(0x2C);

Solomon_VMD(0xC4);
Solomon_VPA(0x00);
Solomon_VPA(0x8E);
Solomon_VPA(0x87);
Solomon_VPA(0x0E);
Solomon_VPA(0x0A);
Solomon_VPA(0x16);
Solomon_VPA(0x87);
Solomon_VPA(0x0E);
Solomon_VPA(0x0A);
Solomon_VPA(0x16);
Solomon_VPA(0x87);
Solomon_VPA(0x0E);
Solomon_VPA(0x0A);
Solomon_VPA(0x16);
Solomon_VPA(0x82);
Solomon_VPA(0x00);
Solomon_VPA(0x03);


Solomon_VMD(0xD0);
Solomon_VPA(0x04);
Solomon_VPA(0x0C);
Solomon_VPA(0x7B);
Solomon_VPA(0x0F);
Solomon_VPA(0x01);
Solomon_VPA(0x03);

Solomon_VMD(0xD7);
Solomon_VPA(0x00);// 20  2DATA
Solomon_VPA(0x00);

Solomon_VMD(0xDE);
Solomon_VPA(0x02);

Solomon_VMD(0xC4);
Solomon_VPA(0x7A);
Solomon_VPA(0x04);

Solomon_VMD(0xB8);
Solomon_VPA(0x1D);
Solomon_VPA(0xA0);
Solomon_VPA(0x2F);
Solomon_VPA(0x04);
Solomon_VPA(0x24);

Solomon_VMD(0xB2);
Solomon_VPA(0x30);
Solomon_VPA(0xF8);
Solomon_VPA(0x93);
Solomon_VPA(0x6E);

Solomon_VMD(0xC1);
Solomon_VPA(0x10);
Solomon_VPA(0x66);
Solomon_VPA(0x66);
Solomon_VPA(0x01);

Solomon_VMD(0xDE);
Solomon_VPA(0x00);

Solomon_VMD(0x3A);
Solomon_VPA(0x05); 	//rgb 666 bit

Solomon_VMD(0x11);  	// SLPOUT
delay_ms(120);

Solomon_VMD(0x2A);
Solomon_VPA(0x00);
Solomon_VPA(0x00);
Solomon_VPA(0x00);
Solomon_VPA(0xEF);

Solomon_VMD(0x2B);
Solomon_VPA(0x00);
Solomon_VPA(0x00);
Solomon_VPA(0x01);
Solomon_VPA(0x1A);

Solomon_VMD(0x2C);

Solomon_VMD(0x29);  	// SLPOUT

	
		
		
	}